<template>
  <div>
    <cascade-category-component :inputData="data"
                                @submitData="articleListHandle"
                                v-if="flag" />
  </div>
</template>

<script>

import CascadeCategoryComponent from './cascade-category-component'
// import floatData from './formatData.json'
import {
  getAllArticleTypeList,
  getChildTypeList,
  getArticleTypeList
} from '@/service/api/backend'
export default {
  name: 'HelloWorld',
  data () {
    return {
      flag: false,
      data: null
    }
  },
  components: {
    CascadeCategoryComponent,
    getAllArticleTypeList,
    getChildTypeList,
    getArticleTypeList
  },
  created () {
    let that = this
    let allData = []
    getAllArticleTypeList().then(res => {
      allData = res.data
      let params = { userId: this.wechatUid }
      getArticleTypeList(params).then(myRes => {
        allData.forEach((element, index, array) => {
          let count = 0
          if (myRes.data.length > 0) {
            myRes.data.forEach((_element, _index, _array) => {
              if (element.id === _element.id && _index > 0) {
                count++
              }
            })
          }
          count > 0 ? element.isSelected = true : element.isSelected = false
        })
        that.data = allData
        console.log(that.data)
        that.flag = true
      })
    })
  },
  methods: {
    articleListHandle () {

    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
